package com.lp.business.service.impl;

import java.util.Date;

import javax.annotation.Resource;

import org.iframework.commons.util.fast.D;
import org.iframework.commons.util.fast.L;
import org.iframework.support.spring.cache.api.BaseCacheConstants;
import org.iframework.support.spring.cache.api.BaseCacheManager;
import org.springframework.stereotype.Component;
/**
 * 获取房源编码的服务类；并用memcached作为缓存服务器保存编号信息
 * @author lipeng
 */
@Component
public class GeneralNumberService {
	@Resource(name = "baseCacheManager")
	private BaseCacheManager memcachedManager;
	
	//房源编码
	public static Integer houseNum = 1000;
	
	/**
	 * 获取房源编码
	 */
	public String getHouseNum() {
		L.i("-----------------CREATE HouseNum BEGIN-----------------");
		Integer HOUSENUM = (Integer) this.memcachedManager.loadObject("FXGY"+"HOUSENUM");
		if (HOUSENUM != null && HOUSENUM > 0) {
			houseNum = HOUSENUM;
		}
		++houseNum;
		this.memcachedManager.cacheObject("FXGY"+"HOUSENUM", houseNum, BaseCacheConstants.CACHE_EXP_FOREVER);
		L.i("-----------------CREATE HouseNum END-----------------");
		String year = D.format(new Date(), "yyyy");
		return year+houseNum.toString();
	}
}